<template>
	<div class="department-set">
		<el-dialog title="设置信箱管理员" :visible.sync="dialogVisible" :close-on-click-modal="false" width="680px">
			<el-form ref="dtemp" style="margin-left: 30px">
				<el-form-item label="选择信箱角色:">
					<el-radio-group v-model="checkedUser.education">
						<el-radio v-for="(item, index) in roleData" :label="item.value">{{ item.label }}</el-radio>
					</el-radio-group>
					<p>
						<font color="#f00">*</font>
						<font color="#999">
							设置信箱管理员会清除之前对应信箱管理员设置并设置“
							<font color="#f90">{{ checkedUser.userName }}</font>
							”为信箱管理员
						</font>
					</p>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button size="medium" @click="dialogVisible = false">取 消</el-button>
				<el-button size="medium" type="primary" v-preventReClick @click="handleSubmit">提 交</el-button>
			</div>
		</el-dialog>
	</div>
</template>
<script>
export default {
	data() {
		return {
			dialogVisible: false,
			checkedUser: {},
			roleData: [
				{ label: '主任信箱', value: '1' },
				{ label: '政委信箱', value: '2' },
				{ label: '建言献策', value: '3' },
				{ label: '监督举报信箱', value: '4' },
				{ label: '机关业务信箱', value: '5' }
			]
		};
	},
	mounted() {
		this.$bus.$on('showDialogmailboxAdministration', this.init);
	},
	beforeDestroy() {
		this.$bus.$off('showDialogmailboxAdministration');
	},
	methods: {
		init(userList) {
			this.checkedUser = userList;
			this.dialogVisible = true;
		},
		async handleSubmit() {
			let res = await this.$store.dispatch('queryTbUserList', { page: 1, limit: 10, education: this.checkedUser.education });
			if (res.data.length > 0) {
				await this.$store.dispatch('updateTbUser', { id: res.data[0].id, education: '' });
			}
			let res3 = await this.$store.dispatch('updateTbUser', { id: this.checkedUser.id, education: this.checkedUser.education });
			this.dialogVisible = false;
			this.$bus.$emit('refreshUserList');
		}
	}
};
</script>
